#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include "scan_task.h"

static const char * module_name = "selfprobe module";
static struct task_struct *ts = NULL;

int scan_thread_start(void){
	int n = 0;
	printk(KERN_ERR"%s creating kthread \n", module_name );
	ts = kthread_run(scan_task, NULL, module_name );
	if( IS_ERR( ts ) ){
		printk(KERN_ERR "%s create kthread failed\n", module_name );
		n = -1;
	}else{
		printk(KERN_ERR"%s create kthread succeed\n", module_name );
	}
	return n;
}

void scan_thread_stop(void){
	printk(KERN_ERR"%s stop kthread\n", module_name );
	kthread_stop(ts);
	return;
}

int scan_task( void * data ){
	printk( KERN_ERR "start scan_task\n");
	while( !kthread_should_stop() ){
		printk( KERN_ERR"in while loop\n");
		msleep(50*1000);
	}
	printk( KERN_ERR "stop scan_task\n");
	return 0;
}
